package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags = "医院管理")
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;
    //通过保存的Mongo中的医院数据来获取医院列表信息
    @ApiOperation("从mongo中查询出医院列表信息")
    @GetMapping("list/{page}/{limit}")
    public Result listHosp(@PathVariable Integer page,
                           @PathVariable Integer limit,
                           HospitalQueryVo hospitalQueryVo
                           ){
        //HospitalQueryVo类  Hospital的抽取类
        //使用mongo进行分页
        Page<Hospital> pageModel = hospitalService.selectHospPage(page,limit,hospitalQueryVo);
        List<Hospital> content =  pageModel.getContent(); //数据内容
        long totalElements = pageModel.getTotalElements(); //总记录数
        log.info("查询的医院数据有{}",pageModel);
        return Result.ok(pageModel);
    }
    @ApiOperation("更新上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable String id ,
                               @PathVariable Integer status){

        hospitalService.updateStatus(id,status);
        return Result.ok();
    }
    @ApiOperation(value = "获取医院详情")
    @GetMapping("show{id}")
    public Result show(@PathVariable String id) {

        //把返回的整体对象，封装进map中更清晰的获取想要的数据
        Map<String, Object> map=hospitalService.show(id);
        return Result.ok(map);
    }

}
